from dataset_builder import DatasetBuilder
from agent_comparator import AgentComparator
from agents import agents10,agents30,agents50,agents70,agents100
from time import strftime

def createRealDatasets(dir = 'topics/'):
    '''
    @return: A dictionary of the real datasets, with their names as keys.
    '''
    builder = DatasetBuilder()
    datasets = {}
    datasets['Windows 7: Features or speed?'] = builder.fromFiles([dir+'features_windows7.txt.data', dir+'speed_windows7.txt.data'])
    datasets['Best Western Hotels: Bath or room?'] = builder.fromFiles([dir+'bathroom_bestwestern_hotel_sfo.txt.data', dir+'rooms_bestwestern_hotel_sfo.txt.data'])
    datasets['Hotels: San Francisco or Chicago?'] = builder.fromFiles([dir+'rooms_bestwestern_hotel_sfo.txt.data', dir+'rooms_swissotel_chicago.txt.data'])
    datasets['Battery life: Which device?'] = builder.fromFiles([dir+'battery-life_amazon_kindle.txt.data', dir+'battery-life_ipod_nano_8gb.txt.data', dir+'battery-life_netbook_1005ha.txt.data'])
    datasets['iPod Nano: Which aspect?'] = builder.fromFiles([dir+'battery-life_ipod_nano_8gb.txt.data', dir+'screen_ipod_nano_8gb.txt.data', dir+'sound_ipod_nano_8gb.txt.data', dir+'video_ipod_nano_8gb.txt.data'])
    return datasets

def runExperiment(name, data, agent1_class, agent2_class, classification_time_limit, learning_time_limit, filename):
    '''
    Runs the comparator with the given parameters and prints its output.
    '''
    path = ''
    
    f = open(path+filename,"a")
    confusion1, confusion2, mcnemar = AgentComparator().run(data, agent1_class, agent2_class, classification_time_limit, learning_time_limit, 10)
    f.write(name+'\n')
    f.write('======================================================='+'\n')
    f.write(str(confusion1)+'\n')
    f.write('======================================================='+'\n')
    f.write(str(confusion2)+'\n')
    f.write('======================================================='+'\n')
    f.write(str(mcnemar)+'\n')
    f.write('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'+'\n')
    f.write('\n')
    f.close()

bagSize = ['10','25','50','75','100']
# Real Data #

def clash(agents,bs):
    datasets = createRealDatasets()
    end = len(agents)
#    print end
    for name, dataset in datasets.items():
        for i in xrange(0,end):
            for j in xrange(i+1,end):
                runExperiment(name, dataset, agents[i], agents[j], 1, 30, bs+str(name).rsplit(":")[0]+'clash.out')
                print bs,i,j,name,strftime(' %H:%M:%S ')
#runs:
clash(agents10,'10')
clash(agents30,'30')
clash(agents50,'50')
clash(agents70,'70')
#clash(agents100,'100')